<?php
/**
 * 扩展
 */

class Extend_CopyfromController extends Cms_AdminController {
	/**
	 * 初始化
	 */
	public function init() {
		parent::init ();
	}
	
	public function indexAction() {
		$DB_Copyfrom = new DB_Copyfrom ();
		$Copyfrom_list = $DB_Copyfrom->loadList ( '*', "", "listorder ASC,id DESC" );
		
		$this->view->assign ( 'Copyfrom_list', $Copyfrom_list );
		$this->render ( 'Extend/copyfrom/index', null, true );
	}
	
	/**
	 * 添加来源
	 */
	public function addAction() {
		$dosubmit = $this->_request->getPost ( 'dosubmit' );
		
		if (isset ( $dosubmit )) {
			$info = $this->_request->getPost ( 'info' );
			
			$Model_Copyfrom = new Model_Copyfrom ();
			if ($Model_Copyfrom->add_Copyfrom ( $info )) {
				$this->view->perRedirect ( '添加管理员成功！', '', '', 'add' );
			} else {
				$this->view->perRedirect ( '添加管理员失败！', '/extend/add/' );
			}
		} else {
			$this->view->setScriptFile ( 'admin/admin_common.js' );
			$this->view->setScriptFile ( 'cookie.js' );
			$this->view->setScriptFile ( 'ckeditor/ckeditor.js' );
			$this->view->setScriptFile ( 'formvalidator.js' );
			$this->view->setScriptFile ( 'formvalidatorregex.js' );
			
			$this->render ( 'Extend/copyfrom/add', null, true );
		}
	}
	
	/**
	 * 编辑来源
	 */
	public function editAction() {
		
		$dosubmit = $this->_request->getPost ( 'dosubmit' );
		
		if (isset ( $dosubmit )) {
			$info = $this->_request->getPost ( 'info' );
			$id = $this->_request->getPost ( 'id' );
			
			$Model_Copyfrom = new Model_Copyfrom ();
			if ($Model_Copyfrom->edit_Copyfrom ( $id, $info )) {
				$this->view->perRedirect ( '修改成功！', '', '', 'edit' );
			} else {
				$this->view->perRedirect ( '修改失败！', "/extend/edit/id/{$id}/" );
			}
		} else {
			$this->view->setScriptFile ( 'admin/admin_common.js' );
			$this->view->setScriptFile ( 'cookie.js' );
			$this->view->setScriptFile ( 'ckeditor/ckeditor.js' );
			$this->view->setScriptFile ( 'swfupload/swf2ckeditor.js' );
			$this->view->setScriptFile ( 'formvalidator.js' );
			$this->view->setScriptFile ( 'formvalidatorregex.js' );
			
			$id = $this->_request->get ( 'id' );
			
			$DB_Copyfrom = new DB_Copyfrom ();
			$Copyfrom_Info = $DB_Copyfrom->loadInfoByPrimary ( $id );
			
			$this->view->assign ( 'id', $id );
			$this->view->assign ( 'Copyfrom_Info', $Copyfrom_Info );
			$this->render ( 'Extend/copyfrom/edit', null, true );
		}
	}
	
	/**
	 * 排序
	 */
	public function listorderAction() {
		$dosubmit = $this->_request->getPost ( 'dosubmit' );
		
		if (isset ( $dosubmit )) {
			$listorders = $this->_request->getPost ( 'listorders' );
			if (is_array ( $listorders )) {
				$DB_Copyfrom = new DB_Copyfrom ();
				foreach ( $listorders as $id => $listorder ) {
					$DB_Copyfrom->updateByPrimary ( array (
							'listorder' => $listorder 
					), $id );
				}
				$this->view->perRedirect ( '操作成功！', '/extend/copyfrom/' );
			}
			$this->view->perRedirect ( '操作失败！', '/extend/copyfrom/' );
		}
		
		$this->view->perRedirect ( '操作失败！', '/extend/copyfrom/' );
	}
}
?>